<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>资料修改</title>
	<script>
		$(document).ready(function() {
			//聚焦第一个输入框
			$("#name").focus();
			//为inputForm注册validate函数
			$("#inputForm").validate();
		});
		
		function modifyPwd() {
			
			if($("#plainPassword").val() == ''){
				alert("密码不能为空");
				return;
			}
			
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/profile/update',
				data : $("#inputForm").serializeArray(),
				dataType : 'json',
				success : function(data) {
					if (data == true) {
						alert("修改密码成功!");
					} else {
						alert("原始密码错误!");
					}
				},
				error : function() {
					alert("获取信息错误！");
				}
			});
		}
	</script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">资料修改</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<form id="inputForm" class="form-horizontal">
		<input type="hidden" name="id" value="${user.id}"/>
		<fieldset>
			<div class="form-group">
				<label for="name" class="col-sm-3 control-label">用户名:</label>
				<div class="col-sm-6">
					<input type="text" id="realname" name="realname" value="${user.realname}" class="form-control input-large required"/>
				</div>
			</div>
			<div class="form-group">
				<label for="plainPassword" class="col-sm-3 control-label">原始密码:</label>
				<div class="col-sm-6">
					<input type="password" id="oldPassword" name="oldPassword" class="form-control input-large required" placeholder=""/>
				</div>
			</div>
			<div class="form-group">
				<label for="plainPassword" class="col-sm-3 control-label">密码:</label>
				<div class="col-sm-6">
					<input type="password" id="plainPassword" name="plainPassword" class="form-control input-large required" onchange="if(!/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/.test(this.value)){alert('密码必须包含 大写字母、小写字母、数字，密码长度 6位以上');this.value='';}" placeholder="必须包含 大写字母、小写字母、数字，密码长度 6位以上"/>
				</div>
			</div>
			<div class="form-group">
				<label for="confirmPassword" class="col-sm-3 control-label">确认密码:</label>
				<div class="col-sm-6">
					<input type="password" id="confirmPassword" name="confirmPassword" class="form-control input-large required" equalTo="#plainPassword" />
				</div>
			</div>
			<div class="modal-footer bg-gray">
				<input id="submit_btn" class="btn btn-primary" type="button" value="提交" onclick="modifyPwd()"/>&nbsp;	
				<input id="cancel_btn" class="btn btn-default" type="button" value="返回" onclick="history.back()"/>
			</div>
		</fieldset>
	</form>
	</div>
	</div>
	</div>
	</div>
	</section>
</body>
</html>
